class SurveyType < ActiveRecord::Base
  has_many :surveys

  def should_show_for_org
    self.tests.size
  end

  def self.find_by_org_id(org_id)
    SurveyType.find_by_sql(" select distinct t1.id, t1.name from survey_types t1 ,
        ( select id, test_type_id from surveys t2 , orgs_surveys t3
            where t2.id = t3.survey_id and t3.org_id = #{org_id}) t4
         where t1.id = t4.test_type_id")
  end
end
